import json
import requests
from datetime import datetime, timedelta
from urllib.parse import urlencode


class MySession(requests.Session):
    def request(self, *args, **kwargs):
        kwargs.setdefault('timeout', 5)
        return super(MySession, self).request(*args, **kwargs)

def lis_new(pid, users):
    cookie_string = ''
    headers = {
                "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
                "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
                "X-Requested-With":"XMLHttpRequest",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                "Cookie":f"JSESSIONID={cookie_string}"
            }
    headers = {
                "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
                "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
                "X-Requested-With":"XMLHttpRequest",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                
            }
   
    url_auth = "http://10.68.1.31:8080/chps/actions/sysLoginAction/login"
    data_auth = {
        "arguments":"String%3A35%7C36%7C31%7C33%3BString%3A30%7C64%7C64%7C62%7C35%7C38%7C37%7C37%7C63%7C38%7C39%7C36%7C66%7C34%7C33%7C65%7C38%7C37%7C33%7C34%7C65%7C31%7C30%7C62%7C30%7C30%7C31%7C65%7C37%7C66%7C31%7C65%7C62%7C39%7C32%7C38%7C38%7C39%7C63%7C64",
      
    }
    # data_auth = urlencode(data_auth)
    # data_auth = json.dumps(data_auth)
    a = users.post(url_auth, headers=headers, json=data_auth)
    print(a.text)
    print(users.cookies.items())

    # url_index = "http://10.68.1.31:8080/chps/jsp/workbench.jsp"
    # b = users.get(url_index, headers=headers, )
    
    # print(users.cookies.items())
    # print(b.text)
    
    # post_data_url = "http://10.68.60.237/ppm/MRTB001.aspx?ajaxMethod=ajaxScan&BCODE=%s&wh_crt=A070112&wh_next=8888&futype=T001&FYJ=&FYJR=&_=1691482366171" % str(pid)
    # post_data_url_cancel = "http://10.68.60.237/ppm/MRTB001.aspx?ajaxMethod=ajaxDelete&fpid=%s&wh_crt=A070112&futype=T001&_=1691482366172" % str(pid)

    # post_data_out = {
    #     "ajaxMethod":"ajaxScan",
    #     "BCODE":str(pid),
    #     "wh_crt":"A070112",
    #     "wh_next":"8888",
    #     "futype":"T001",
    #     "FYJ":"",
    #     "FYJR":"",
    #     "_":"1691467189180",
    # }
    # post_data_cancel = {
    #     "ajaxMethod":"ajaxDelete",
    #     "fpid":str(pid),
    #     "wh_crt":"A070112",
    #     "futype":"T001",
    #     "_":"1691467189181",
    # }

    # get_post_data_out = users.get(
    #      post_data_url_cancel,
       
    #     headers=headers
    #  )
    # if get_post_data_out.status_code != 200:
    #     raise Exception('网络访问失败')
    
    # print(get_post_data_out.text)

if __name__ == "__main__":

    users = MySession()
    print(lis_new(2023000048,users))
